<script setup lang="ts">
import { onMounted, ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "@/views/system/hooks";
const { switchStyle } = usePublicHooks();
//import { Plus } from "@element-plus/icons-vue";
//import type { UploadProps } from "element-plus";
//import { getToken } from "@/utils/auth";
//import getURL from "@/utils/http/address";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: 0,
    comID: "",
    comName: "",
    comType: "",
    comUser: "",
    comAddress: "",
    comPhone: "",
    tokenCount: 0,
    isFalg: 0,
    addUser: "1",
    addTime: "2024-8-9"
  })
});
usePublicHooks();
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
//const headers = ref();
const isEdit = ref(true);
//const uploadAddress = ref();
function getRef() {
  return ruleFormRef.value;
}

//const imageUrl = ref("");

// const handleAvatarSuccess: UploadProps["onSuccess"] = (
//   response,
//   uploadFile
// ) => {
//   console.log("uploadFile", uploadFile);
//   console.log("response", response);
//   imageUrl.value = URL.createObjectURL(uploadFile.raw!);
//   newFormInline.value.aiHead = "/wwwroot/aihead/" + response.result;
// };

// const beforeAvatarUpload: UploadProps["beforeUpload"] = rawFile => {
//   if (rawFile) return true;
// };
onMounted(() => {
  if (newFormInline.value.comID == "") {
    isEdit.value = false;
  }
  // headers.value = { Authorization: "Bearer " + getToken().accessToken };
  // uploadAddress.value = getURL + "/api/System/uploadAIHeade";
  // if (newFormInline.value.aiHead) {
  //   imageUrl.value = getURL + newFormInline.value.aiHead;
  // }
});
defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    label-position="top"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="机构编码" prop="comID">
      <el-input
        v-model="newFormInline.comID"
        clearable
        placeholder="请输入机构编码"
        :disabled="isEdit"
      />
    </el-form-item>
    <el-form-item label="机构名称" prop="comName">
      <el-input
        v-model="newFormInline.comName"
        clearable
        placeholder="输入机构名称"
      />
    </el-form-item>
    <el-form-item label="机构类型" prop="comType">
      <el-select v-model="newFormInline.comType">
        <el-option value="个人">个人</el-option>
        <el-option value="团队">团队</el-option>
        <el-option value="企业">企业</el-option>
        <el-option value="政府">政府</el-option>
        <el-option value="事业单位">事业单位</el-option>
        <el-option value="其它">其它</el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="机构负责人" prop="comUser">
      <el-input v-model="newFormInline.comUser" type="text" clearable />
    </el-form-item>
    <el-form-item label="机构地址" prop="comAddress">
      <el-input v-model="newFormInline.comAddress" clearable type="text" />
    </el-form-item>
    <el-form-item label="机构电话" prop="comPhone">
      <el-input v-model="newFormInline.comPhone" clearable type="text" />
    </el-form-item>
    <!-- <el-form-item label="Token数" prop="tokenCount">
      <el-input v-model="newFormInline.tokenCount" type="text" disabled />
    </el-form-item> -->
    <el-form-item label="是否启用" prop="isFalg">
      <el-switch
        v-model="newFormInline.isFalg"
        inline-prompt
        :active-value="1"
        :inactive-value="0"
        active-text="启用"
        inactive-text="停用"
        :style="switchStyle"
      />
    </el-form-item>
  </el-form>
</template>
<style>
.box {
  width: 100%;
  height: 300px;
  border: 1px solid rgb(185 182 182);
}

.code {
  width: 300px;
  height: 100%;
  font-size: 18px;
}
</style>
